var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
    })(t, e);
}, function(t, e) {
    function n() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (n.prototype = e.prototype, 
    new n());
}), a = this && this.__decorate || function(t, e, o, n) {
    var i, r = arguments.length, a = r < 3 ? e : null === n ? n = Object.getOwnPropertyDescriptor(e, o) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(t, e, o, n); else for (var s = t.length - 1; 0 <= s; s--) (i = t[s]) && (a = (r < 3 ? i(a) : 3 < r ? i(e, o, a) : i(e, o)) || a);
    return 3 < r && a && Object.defineProperty(e, o, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
}), n.GunType = void 0;

var r, s = e("Global"), c = e("AudioManager"), l = e("TimeView"), d = e("PoolManager"), u = e("GameData"), p = e("EggsManager"), h = e("LoadManager"), f = e("UIManager"), g = cc._decorator, m = g.ccclass, y = g.property;

!function(t) {
    t[t.DEFAULT = 0] = "DEFAULT", t[t.EGGS = 1] = "EGGS", t[t.DRAW = 2] = "DRAW", t[t.OLYMPIC = 3] = "OLYMPIC";
}(r = n.GunType || (n.GunType = {}));

var v = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.sprite = null, t.profitLabel = null, t.box = null, t.rank = null, t.type = r.DEFAULT, 
        t.isEffect = !1, t.timeView = null, t;
    }
    return i(t, e), t.prototype.onLoad = function() {
        this.profitLabel && (cc.Tween.stopAllByTarget(this.profitLabel.node), this.profitLabel.node.active = !1);
    }, t.prototype.onEnable = function() {
        var t;
        this.type == r.EGGS && this.timeView && (0 < (t = p.default.getInstance().checkEggTimeGun(this.rank)) ? (this.doTimer(t), 
        h.default.getInstance().loadSpriteFrame({
            url: "image/arm3/" + this.rank,
            sprite: this.sprite
        })) : this.clearEgg());
    }, t.prototype.start = function() {}, t.prototype.init = function(t) {
        this.box = t;
    }, t.prototype.refresh = function() {
        var t;
        this.type == r.DRAW ? h.default.getInstance().loadSpriteFrame({
            url: "image/arm_draw/" + this.rank,
            sprite: this.sprite
        }) : this.type == r.EGGS ? 0 < (t = p.default.getInstance().checkEggTimeGun(this.rank)) ? (this.doTimer(t), 
        h.default.getInstance().loadSpriteFrame({
            url: "image/arm3/" + this.rank,
            sprite: this.sprite
        })) : this.clearEgg() : (this.profitLabel || (t = f.default.getInstance().getPnl("start")) && (this.profitLabel = t.getProfit().getComponent(cc.Label), 
        this.profitLabel.node.parent = this.node), this.profitLabel && (this.profitLabel.string = "+" + GA.formatNumber(s.G.getProfit(this.rank))), 
        h.default.getInstance().loadSpriteFrame({
            url: "image/arm/" + s.G.getIdxByRank(this.rank),
            sprite: this.sprite
        }));
    }, t.prototype.show = function() {
        this.type == r.DEFAULT && this.schedule(this.showProfit, 5 * Math.random() + 3);
    }, t.prototype.clear = function() {
        var t;
        this.profitLabel && this.profitLabel.node && (this.profitLabel.node.active = !1, 
        (t = f.default.getInstance().getPnl("start")) && (t.profitPool.put(this.profitLabel.node), 
        this.profitLabel = null)), this.node.destroy();
    }, t.prototype.check = function(t) {
        return this.type == r.DEFAULT && t.type == r.DEFAULT && t.rank == this.rank && this.rank < s.G.gunModelList.length - 1;
    }, t.prototype.combine = function(t, e, o) {
        void 0 === e && (e = null), void 0 === o && (o = !0), t.box.item = null, t.box.refresh(), 
        o ? (t.isEffect = !0, this.isEffect = !0, this.doEffect(t, e)) : (this.rank++, this.refresh(), 
        this.box.refresh(), t.node.destroy(), e && e());
    }, t.prototype.doEffect = function(e, o) {
        var n = this;
        e.node.setPosition(e.node.parent.convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.Vec2.ZERO))), 
        cc.tween(e.node).by(.2, {
            position: cc.v3(80, 0)
        }).by(.2, {
            position: cc.v3(-80, 0)
        }).start(), cc.tween(this.node).by(.2, {
            position: cc.v3(-80, 0)
        }).by(.2, {
            position: cc.v3(80, 0)
        }).start(), d.default.getInstance().getSkeleton({
            url: "skeleton/combine/skeleton"
        }).then(function(t) {
            t.node.parent = n.node, n.scheduleOnce(function() {
                c.default.getInstance().playAudio("合成音效1", 2), n.isEffect = !1, t.node.active = !0, 
                t.setAnimation(0, "animation", !1), t.setCompleteListener(function() {
                    d.default.getInstance().putSkeleton(t.node);
                }), n.rank++, u.GD.topRank < n.rank && u.GD.topRank++, n.refresh(), n.box.refresh(), 
                e.clear(), o && o();
            }, .5);
        });
    }, t.prototype.showProfit = function() {
        var t, e = this;
        this.isEffect || (cc.tween(this.sprite.node).to(.2, {
            scale: 1.1
        }).to(.1, {
            scale: 1
        }).start(), (t = f.default.getInstance().getPnl("start")) && (this.profitLabel || (this.profitLabel = t.getProfit().getComponent(cc.Label), 
        this.profitLabel.node.parent = this.node), this.profitLabel && (this.profitLabel.node.active = !0, 
        this.profitLabel.string = "+" + GA.formatNumber(s.G.getProfit(this.rank)), cc.Tween.stopAllByTarget(this.profitLabel.node), 
        this.profitLabel.node.setPosition(cc.v2(0, 40)), this.profitLabel.node.opacity = 255, 
        cc.tween(this.profitLabel.node).parallel(cc.tween().to(.8, {
            opacity: 0
        }), cc.tween().by(.5, {
            position: cc.v2(0, 50)
        }), cc.tween().to(.2, {
            scale: 1.1
        }).to(.2, {
            scale: 1
        })).call(function() {
            e.profitLabel.node.active = !1, t.profitPool.put(e.profitLabel.node), e.profitLabel = null;
        }).start())));
    }, t.prototype.clearEgg = function() {
        var t = p.default.getInstance().getDataGun(this.rank);
        t && (t.time = 0, p.default.getInstance().setDataGun(this.rank, t));
        t = f.default.getInstance().getPnl("start");
        t ? (u.GD.gunIdx == -this.rank - 1 && (u.GD.gunIdx = u.GD.topRank, t.personView.changeGun(u.GD.topRank)), 
        this.box ? this.box.removeItem() : this.clear(), t.updateMatrix()) : this.box ? this.box.removeItem() : this.clear();
    }, t.prototype.getTimer = function() {
        var n = this;
        return new Promise(function(e, o) {
            n.timeView ? e(n.timeView) : h.default.getInstance().loadRes({
                url: "prefab/time",
                type: cc.Prefab
            }).then(function(t) {
                n.timeView = cc.instantiate(t).getComponent(l.default), n.timeView ? (n.timeView.node.parent = n.node, 
                e(n.timeView)) : o();
            }).catch(function() {
                o();
            });
        });
    }, t.prototype.doTimer = function(e) {
        var o = this;
        this.getTimer().then(function(t) {
            t.init(Math.floor(e / 1e3)), t.startTimer(), t.node.on("finished", o.clearEgg, o);
        });
    }, a([ y(cc.Sprite) ], t.prototype, "sprite", void 0), a([ m ], t);
}(cc.Component);

n.default = v;